package org.csmzxy.xg2333;

import java.util.Scanner;

public class example01 {

        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入一个整数: ");
            int number = scanner.nextInt();

            if (isNarcissisticNumber(number)) {
                System.out.println(number + " 是水仙花数。");
            } else {
                System.out.println(number + " 不是水仙花数。");
            }

            scanner.close();
        }

        // 判断一个数是否是水仙花数
        public static boolean isNarcissisticNumber(int number) {
            if (number < 0) {
                return false;
            }

            int originalNumber = number;
            int n = String.valueOf(number).length();
            int sum = 0;

            while (number != 0) {
                int digit = number % 10;
                sum += Math.pow(digit, n);
                number /= 10;
            }

            return sum == originalNumber;
        }
    }
